/**
 * @Title: Modal4.js
 * @Description: Modal4
 * @author: Fanchao
 * @date: 2021/2/14 3:03 下午
 * @version V1.0
 */
import React from 'react';
import { connect } from 'umi';
import { Form, InputNumber, Modal, Select } from 'antd';

const layout = {
    labelCol: { span: 6 },
    wrapperCol: { span: 18 },
};
const optionConfig = {
    '优秀': 'best',
    '良好': 'good',
    '合格': 'pass',
};
const { Option } = Select;
const Modal4 = ({ computeScheme: { tab4List, tab4Show, item4Data }, dispatch }) => {
    const [form] = Form.useForm();
    form.setFieldsValue({
        studentEvaluateLowerRatio: tab4List[0]?.conditionValue,
        schoolExpertEvaluateLowerRatio: tab4List[1]?.conditionValue,
        teachSectionEvaluateResult: optionConfig[tab4List[2]?.conditionValue],
        centerEvaluateResult: optionConfig[tab4List[3]?.conditionValue],
    });
    return (
        <Modal
            title={'添加/修改合格等级确定条件'}
            visible={tab4Show}
            width="800px"
            onOk={() => {
                form.validateFields().then(values => {
                    if (item4Data.passResultConditionId) {
                        // values.passResultConditionId = item4Data.passResultConditionId;
                        dispatch({
                            type: 'computeScheme/updateTab4Item',
                            payload: values,
                            callback: (result) => {
                                if (result) {
                                    form.resetFields();
                                    dispatch({
                                        type: 'computeScheme/setItem4Data',
                                        payload: {},
                                    });
                                    dispatch({
                                        type: 'computeScheme/setTab4Show',
                                        payload: false,
                                    });
                                    dispatch({
                                        type: 'computeScheme/getTab4List',
                                    });
                                }
                            },
                        });
                    } else {
                        dispatch({
                            type: 'computeScheme/addTab4Item',
                            payload: values,
                            callback: (result) => {
                                if (result) {
                                    form.resetFields();
                                    dispatch({
                                        type: 'computeScheme/setItem4Data',
                                        payload: {},
                                    });
                                    dispatch({
                                        type: 'computeScheme/setTab4Show',
                                        payload: false,
                                    });
                                    dispatch({
                                        type: 'computeScheme/getTab4List',
                                    });
                                }
                            },
                        });
                    }
                }).catch(info => {
                });
            }}
            onCancel={() => {
                form.resetFields();
                dispatch({
                    type: 'computeScheme/setItem4Data',
                    payload: {},
                });
                dispatch({
                    type: 'computeScheme/setTab4Show',
                    payload: false,
                });
            }}
        >
            <Form
                {...layout}
                layout="horizontal"
                form={form}
                name="basic"
                // 表单默认值，只有初始化以及重置时生效 莫用
                initialValues={{
                    // name: item4Data.name
                }}
            >
                <Form.Item
                    label="学员评价排序位于部系后"
                    name="studentEvaluateLowerRatio"
                    rules={[{ required: true, message: '必填' }]}
                >
                    <InputNumber
                        min={0}
                        max={99}
                        step={0.1}
                        formatter={value => `${value}%`}
                        parser={value => value.replace('%', '')}
                        style={{ width: '100%' }}
                        placeholder="请输入学员评价排序位于部系后比例权重"
                    />
                </Form.Item>
                <Form.Item
                    label="校专家评价排序位于部系后"
                    name="schoolExpertEvaluateLowerRatio"
                    rules={[{ required: true, message: '必填' }]}
                >
                    <InputNumber
                        min={0}
                        max={99}
                        step={0.1}
                        formatter={value => `${value}%`}
                        parser={value => value.replace('%', '')}
                        style={{ width: '100%' }}
                        placeholder="请输入校专家评价排序位于部系后比例权重"
                    />
                </Form.Item>
                <Form.Item
                    label="教研室评价结论为"
                    name="teachSectionEvaluateResult"
                    rules={[{ required: true, message: '必填' }]}
                >
                    <Select
                        placeholder="请选择教研室评价结论"
                    >
                        <Option value="best">优秀</Option>
                        <Option value="good">良好</Option>
                        <Option value="pass">合格</Option>
                    </Select>
                </Form.Item>
                <Form.Item
                    label="部系评价结论"
                    name="centerEvaluateResult"
                    rules={[{ required: true, message: '必填' }]}
                >
                    <Select
                        placeholder="请选择部系评价结论"
                    >
                        <Option value="best">优秀</Option>
                        <Option value="good">良好</Option>
                        <Option value="pass">合格</Option>
                    </Select>
                </Form.Item>
            </Form>
        </Modal>
    );
};
export default connect(({ computeScheme, dispatch }) => ({
    computeScheme,
    dispatch,
}))(Modal4);

